package com.example.reagent_management;

import android.util.Log;

import androidx.annotation.NonNull;
import androidx.hilt.work.HiltWorkerFactory;
import androidx.work.Configuration;

import com.example.lib_base.base.BaseApplication;
import com.example.lib_base.utils.ktx.UtilsConfig;
import com.hjq.toast.ToastUtils;
import com.tencent.mmkv.MMKV;

import javax.inject.Inject;

import dagger.hilt.android.HiltAndroidApp;
/*
* 关于hilt依赖注入可查看官方文档，提供对象注入，以及管理注入组件的生命周期，减少内存泄露以及代码的编写
*   https://developer.android.google.cn/training/dependency-injection/hilt-android#application-class
*
*   整个应用起点 hiltAndroidApp
* */
@HiltAndroidApp
public class App extends BaseApplication implements Configuration.Provider {

    @Inject
    HiltWorkerFactory hiltFactory;

    @Override
    public void onCreate() {
        super.onCreate();
        //Toast 在哪都可Toast里面用了反射改成自己的Handler 还在维护支持Android12
        ToastUtils.init(this);
        //MMKV 微信都在用的高效key-value存储
        MMKV.initialize(this);
        UtilsConfig.Companion.init(this);
    }


    @NonNull
    @Override
    public Configuration getWorkManagerConfiguration() {
        //设置workManager最小日志级别
        Configuration.Builder builder = new Configuration.Builder();
        builder.setWorkerFactory(hiltFactory);
        if (BuildConfig.DEBUG){
            builder.setMinimumLoggingLevel(Log.DEBUG);
        }else {
            builder.setMinimumLoggingLevel(Log.ERROR);
        }
        return builder.build();
    }

}
